package com.zhsj.OkeHomeConsumption.ui.activity.wallet;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.empty.CitypantnerRemake;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.CityUIInterFace;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.CitypayeePresenter;
import com.zhsj.OkeHomeConsumption.utils.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 城市合伙人--我的钱包
 */
public class CityWalletActivity extends MyActivity implements CityUIInterFace {


    @BindView(R.id.yue_text)
    TextView yueText;
    @BindView(R.id.zongshouru_text)
    TextView zongshouruText;
    @BindView(R.id.zongshouru)
    LinearLayout zongshouru;
    @BindView(R.id.yitixian_text)
    TextView yitixianText;
    @BindView(R.id.yitixian)
    LinearLayout yitixian;
    @BindView(R.id.yujishouru_text)
    TextView yujishouruText;
    @BindView(R.id.yujishouru)
    LinearLayout yujishouru;
    @BindView(R.id.lin)
    LinearLayout lin;

    private LinearLayout jifenlin;

    private FormalUserInfo userInfo;
    private CitypantnerRemake remake;
    private CitypayeePresenter minePersonPresenter;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_wallet;
    }

    @Override
    protected int getTitleId() {
        return R.id.title;
    }

    protected void initView() {
        userInfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);
        minePersonPresenter = new CitypayeePresenter(getActivity(), this);
    }

    @Override
    protected void initData() {
        minePersonPresenter.WalletGet();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.zongshouru, R.id.yitixian, R.id.yujishouru, R.id.lin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.zongshouru:
                break;
            case R.id.yitixian:
                break;
            case R.id.yujishouru:
                break;
            case R.id.lin:
                startActivity(MinewalletActivity.class);
                break;
        }
    }

    @Override
    public void WalletGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONObject jsonobj = jsonOBJ.optJSONObject("data");
                // 数据对接正常
                remake = JsonUtils.object(jsonobj.toString(), CitypantnerRemake.class);

                //总收入
                zongshouruText.setText(remake.getTotalIncome());
                //已提现
                yitixianText.setText(remake.getExtractCash() + "");
                //预计收入
                yujishouruText.setText(remake.getLaveMoney()+ "");
                //可提现
                yueText.setText(remake.getAllowCash()+"");

            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("ShopListGet", "钱包");
        }
    }

}
